//
//  PopoverPresentationController.swift
//  TTWeibo
//
//  Created by 唐磊guang on 16/7/5.
//  Copyright © 2016年 唐磊guang. All rights reserved.
//

import UIKit

class PopoverPresentationController: UIPresentationController {
    
    var myDifineFrame: CGRect =  CGRectMake(100, 56, 200, 200)
    
    
    override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
    }
    
    override func containerViewWillLayoutSubviews() {
        presentedView()?.frame = myDifineFrame
        containerView?.insertSubview(coverView, atIndex: 0)
        
    }
    
    private lazy var coverView:UIView = {
        let cv = UIView()
        cv.frame = UIScreen.mainScreen().bounds
        cv.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        let tap = UITapGestureRecognizer(target: self, action: #selector(PopoverPresentationController.dissmissDrop))
        cv.addGestureRecognizer(tap)
        return cv
    }()
    func dissmissDrop() {
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
}
